Introduction

Today’s map shows the locations of Philadelphia’s historic sites visualized on OpenStreetMap. Today, all properties of historical places in Philadelphia is managed by the City of Philadelphia, by undergoing a nomination process and being added to the register.

Setup

knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(tidycensus)
library(mapview)
library(sf)
library(viridis)
library(ggtext)
library(showtext)
library(maps)
library(ggplot2)
library(cowplot)
library(httr)
remotes::install_github("mikejohnson51/climateR")
font_add_google("Roboto", "roboto")
showtext_auto(TRUE)

plotTheme <- theme(
  plot.title = element_text(face="bold", hjust = 0, size=10, lineheight=0.8),
  plot.subtitle = element_text(hjust = 0, size = 6, face = "italic", lineheight=0.8, margin = margin(b = 3, t = 6)),  
        plot.caption = element_text(size = 5, hjust = 0, lineheight=0.9),
        plot.margin = margin(1.7, 1.7, 1.7, 1.7),
        text = element_text(family = "roboto"),
        legend.position="none") 

Loading Data

# Set ACS API Key
census_api_key("b2835f54d89a4499ba29829c908967b86765b345", overwrite = TRUE)

# Load ACS data (for boundary)
tracts22_pa <-  
  get_acs(geography = "tract",
          variables = c("B08134_001E"), 
          year=2022, state="PA",
          geometry=TRUE, progress=FALSE) %>%
    st_union() %>%
  st_transform(crs = 'EPSG:32618')

tracts22_nj <-  
  get_acs(geography = "tract",
          variables = c("B08134_001E"), 
          year=2022, state="NJ",
          geometry=TRUE, progress=FALSE) %>%
  st_union() %>%
  st_transform(crs = 'EPSG:32618')

tracts20 <-  
  get_acs(geography = "tract",
          variables = c("B25034_001E"), 
          year=2020, state="PA",
          county="Philadelphia", geometry=TRUE, progress=FALSE) %>% 
  st_as_sf(crs = 4326)%>%
  st_transform('EPSG:32618') # Use NAD 83 CRS

# Load Historical Places Data
historicPlaces <- readxl::read_xlsx('./data/Phila-Reg-No-OPA-6-26-2024.xlsx')
historicPlaces_trans <- historicPlaces %>%
  st_as_sf(coords=c("lng","lat"), crs=4326) %>%
  st_transform('EPSG:32618') # Use NAD 83 CRS

url1 <- "https://services.arcgis.com/fLeGjb7u4uXqeF9q/arcgis/rest/services/Historic_Streets/FeatureServer/0/query?where=1=1&outFields=*&f=geojson"

url2 <- "https://services.arcgis.com/fLeGjb7u4uXqeF9q/arcgis/rest/services/HistoricDistricts_Local/FeatureServer/0/query?where=1=1&outFields=*&f=geojson"

url3 <- "https://services.arcgis.com/fLeGjb7u4uXqeF9q/arcgis/rest/services/Historic_sites_PhilReg/FeatureServer/0/query?where=1=1&outFields=*&f=geojson"
response1 <- GET(url1)
response2 <- GET(url2)
response3 <- GET(url3)
json_data <- content(response1, as = "text", encoding = "UTF-8", progress=FALSE)
json_data2 <- content(response2, as = "text", encoding = "UTF-8", progress=FALSE)
json_data3 <- content(response3, as = "text", encoding = "UTF-8", progress=FALSE)

# Transformation of Coordinate System
historicStreets <- st_read(json_data) %>%
  st_as_sf(crs = 4326) %>%
  st_transform(crs = 'EPSG:32618') 

historicDistricts <- st_read(json_data2) %>%
  st_as_sf(crs = 4326) %>%
  st_transform(crs = 'EPSG:32618') 

historicSites <- st_read(json_data3) %>%
  st_as_sf(crs = 4326) %>%
  st_transform(crs = 'EPSG:32618') 

Plotting, Exporting and Printing

mv <- mapview(st_union(tracts20), label = NULL, popup = NULL, lwd = 3, color = "#0FF", col.regions = "transparent", alpha = 0.7, map.types = "OpenStreetMap") +
  mapview(historicPlaces_trans, label = "Resource Name", col.regions = "#0ff", alpha = 1.0, cex = 3, layer.name="Historic Sites (additional)")+
  mapview(historicDistricts, label = "NAME", col.regions = "#0ff", alpha = 1.0, cex = 3, layer.name="Historic Districts")+
  mapview(historicStreets, label = "ON_STREET", col.regions = "#00f", alpha = 1.0, cex = 3, layer.name="Historic Streets")+
  mapview(historicSites, label = "LOC", col.regions = "#0ff", alpha = 1.0, cex = 3, layer.name="Historic Sites")
historicDistricts$category <- "Districts and Sites"
historicStreets$category <- "Streets"
historicSites$category <- "Districts and Sites"
historicSites$datemdy <- mdy(historicSites$DISTRICTDESDATE)
historicSites$year <- year(historicSites$datemdy)

category_colors <- c(
  "Districts and Sites" = "#335599",      
  "Streets" = "#3357FF",       
  "Additional Sites" = "#FFC300"  
)

map4 <- ggplot() + 
  geom_sf(data = tracts22_pa, fill = "#ddd", color = "#fff") +
  geom_sf(data = tracts22_nj, fill = "#ccc", color = "#fff") +
  geom_sf(data=st_union(tracts20), color="#fff") +
  geom_sf(data=historicDistricts, aes(color = category)) +
  geom_sf(data=historicStreets, aes(color = category)) +
  geom_sf(data=historicSites, aes(color = category)) +
  geom_point(
    data=historicPlaces_trans, aes(geometry=geometry, color = "Additional Sites"), 
    stat = "sf_coordinates", size=0.5)+
  xlim(475000, 505000) +  # Set x-axis limits for the map (longitude range)
  ylim(4412000, 4443000) +  # Set y-axis limits for the map (latitude range)
  theme_void(base_size = 14) +
  labs(
    title = "Historical Places in Philadelphia",
    subtitle = "October, 2024",
    caption = "Data: City of Philadelphia",
    color = "") +
  scale_color_manual(values = category_colors) +
  plotTheme
mv
map4

Reference

https://www.phila.gov/documents/philadelphia-register-of-historic-places/